package com.frank.dto;

import org.apache.ibatis.session.RowBounds;

import java.util.HashMap;

/**
 * 通用页面信息，分页搜索等等
 */
public class QueryPageDto {
    /**
     * 搜索key
     */
    private String searchKey;
    /**
     * 排序字段
     */
    private String column;
    /**
     * 排序顺序
     */
    private String order;
    /**
     * 页大小
     */
    private Integer pageSize;
    /**
     * 第几页
     */
    private Integer currentPage;

    /**
     * 工具方法，返回bounds
     * @return
     */
    public RowBounds getRowBounds() {
        RowBounds rowBounds;
        if(currentPage==null||currentPage<=0||pageSize==null||pageSize<=0){
            return new RowBounds();
        }
        rowBounds = new RowBounds((currentPage-1)*pageSize, pageSize);
        return rowBounds;
    }

    public HashMap<String, String> getMap(){
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("searchKey",searchKey);
        hashMap.put("column",column);
        hashMap.put("order",order);
        return hashMap;
    }

    public String getSearchKey() {
        return searchKey;
    }

    public void setSearchKey(String searchKey) {
        this.searchKey = searchKey;
    }

    public String getColumn() {
        return column;
    }

    public void setColumn(String column) {
        this.column = column;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    @Override
    public String toString() {
        return "QueryPageDto{" +
                "searchKey='" + searchKey + '\'' +
                ", column='" + column + '\'' +
                ", order='" + order + '\'' +
                ", pageSize=" + pageSize +
                ", currentPage=" + currentPage +
                '}';
    }
}
